package cn.kin.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.kin.dao.TimetablesMapper;
import cn.kin.pojo.Timetables;
import cn.kin.service.TimetablesService;

//课程表
@Service
public class TimetablesServiceImpl implements TimetablesService{

	@Resource
	private TimetablesMapper timetablesMapper;
	
	@Override
	public List<Timetables> findByClassID(Integer classID,Integer next) {
		// TODO Auto-generated method stub
		try {
			List<Timetables> list=null;
			list=timetablesMapper.selectByClass(classID,next);
			if(list!=null&&list.size()==0) {
				int result=timetablesMapper.insertTimetables(classID, next);
				if(result>0) {
					list=timetablesMapper.selectByClass(classID,next);
				}
			}
			return list;
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return null;
	}
	
	@Override
	public boolean updateTimetables(List<Timetables> list) {
		// TODO Auto-generated method stub
		boolean result=true;
		try {
			for(Timetables t : list) {
				if(timetablesMapper.updateByTimetables(t)<1){
					result=false;
				}
			}
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			result=false;
		}
		return result;
	}
	
	@Override
	public boolean delHistory() {
		// TODO Auto-generated method stub
		try {
			timetablesMapper.deleteByDate();
			return true;
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return false;
	}
}
